package com.heima.controller;

import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.NewsAuthDto;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author chenshan
 */
@RestController
@RequestMapping("api/v1/news")
public class NewsController {
    @Autowired
    private NewsService newsService;

    /**
     * 分页条件查询文章列表
     * @param dto 分页+条件
     * @return PageResponseResult
     */
    @PostMapping("list")
    public PageResponseResult newsList(@RequestBody WmNewsPageReqDto dto) {
        return newsService.newsList(dto);
    }

    /**
     * 自媒体端文章的发布功能
     * @param newsDto 文章信息
     * @return ResponseResult
     */
    @PostMapping("submit")
    public ResponseResult newsSubmit(@RequestBody WmNewsDto newsDto, @RequestParam Boolean draft) throws Exception {
        return newsService.newsSubmit(newsDto, draft);
    }

    /**
     * 根据id查询文章详情
     * @param id 文章id
     * @return ResponseResult 文章详情
     */
    @GetMapping("one/{id}")
    public ResponseResult selectNewsById(@PathVariable Integer id) {
        return ResponseResult.okResult(newsService.getById(id));
    }

    /**
     * 文章的上架或下架
     * @param news 文章信息
     * @return ResponseResult
     */
    @PostMapping("down_or_up")
    public ResponseResult newsDownOrUp(@RequestBody WmNews news) {
        return newsService.newsDownOrUp(news);
    }

    /**
     * 查询自媒体文章列表
     * @param authDto 自媒体文章信息
     * @return ResponseResult
     */
    @PostMapping("list_vo")
    public ResponseResult findAllNews(@RequestBody NewsAuthDto authDto) {
        return newsService.findAllNews(authDto);
    }

    /**
     * 查询自媒体文章详情
     * @param id 自媒体文章id
     * @return ResponseResult
     */
    @GetMapping("one_vo/{id}")
    public ResponseResult findNewById(@PathVariable Integer id) {
        return newsService.findNewById(id);
    }

    /**
     * 自媒体文章审核驳回
     * @param authDto 自媒体文章驳回信息
     * @return ResponseResult
     */
    @PostMapping("auth_fail")
    public ResponseResult authFailNews(@RequestBody NewsAuthDto authDto) {
        return newsService.authFailNews(authDto);
    }

    /**
     * 自媒体文章审核通过
     * @param authDto 自媒体文章通过信息
     * @return ResponseResult
     */
    @PostMapping("auth_pass")
    public ResponseResult authPassNews(@RequestBody NewsAuthDto authDto) {
        return newsService.authPassNews(authDto);
    }

    /**
     * 本地自定义敏感词校验（DFA校验）
     * @param content 检测内容
     * @return ResponseResult<Boolean>
     */
    @PostMapping("content")
    public ResponseResult<Boolean> checkContent(@RequestBody String content) {
        return newsService.checkContent(content);
    }

}
